Imports System.Data.SqlClient
Public Class Propiedades
    Dim da As New DataAccess
    Dim millamador As llamadores
    Dim combo As New combo

    Enum llamadores
        ABMPropiedades
        Contratos
        EstadoCuentas
    End Enum
    Public Property llamador() As llamadores
        Get
            Return millamador
        End Get
        Set(ByVal value As llamadores)
            millamador = value
        End Set
    End Property
    Private Sub Propiedades_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cargarGrilla()
        cargarCombo()
    End Sub
    Private Sub cargarGrilla()
        If (Me.txtBuscar.Text = "") Then
            Dim sql As String = "select * from PropiedadesCompletas"
            Me.DataGridView1.DataSource = da.consultarSQL(sql)
        Else
            If Me.validarDatos() = False Then
                Exit Sub
            End If
            Dim cmd As New SqlCommand
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "usp_buscarPropiedades"
            cmd.Parameters.AddWithValue("columna", Me.cmbCampo.SelectedValue.ToString())
            cmd.Parameters.AddWithValue("texto", Me.txtBuscar.Text)
            DataGridView1.DataSource = da.consultarSP(cmd)
        End If
        
        Me.DataGridView1.Columns(0).HeaderText = "Codigo"
        Me.DataGridView1.Columns(1).HeaderText = "Tipo"
        Me.DataGridView1.Columns(2).HeaderText = "Calle"
        Me.DataGridView1.Columns(3).HeaderText = "Nro"
        Me.DataGridView1.Columns(4).HeaderText = "Piso"
        Me.DataGridView1.Columns(5).HeaderText = "Dpto"
        Me.DataGridView1.Columns(6).HeaderText = "Barrio"
        Me.DataGridView1.Columns(7).HeaderText = "Localidad"
        Me.DataGridView1.Columns(8).HeaderText = "Provincia"
        Me.DataGridView1.Columns(9).HeaderText = "Precio"
        Me.DataGridView1.Columns(10).HeaderText = "Comision"
        Me.DataGridView1.Columns(11).HeaderText = "Propietario"
    End Sub
    Private Function validarDatos() As Boolean
        Return True
    End Function
    Private Sub cargarCombo()
        Dim tabla As New DataTable
        tabla = da.leerColumnasTabla("PropiedadesCompletas")
        combo.cargar(Me.cmbCampo, tabla, "columna", "columna")
    End Sub

    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click
        cargarGrilla()
    End Sub

    Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick

    End Sub

    Private Sub DataGridView1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDoubleClick
        Try
            Dim indice As Integer = Me.DataGridView1.SelectedRows(0).Index
            Select Case Me.llamador
                Case llamadores.ABMPropiedades
                    Dim ABMProp1 As New ABMPropiedades
                    ABMProp1 = Inmobiliaria.Menu.getABMPropiedad
                    Me.Hide()
                    ABMProp1.Show()
                    ABMProp1.Focus()
                    ABMProp1.txtNroProp.Text = Me.DataGridView1.SelectedCells.Item(0).Value
                    ABMProp1.Button2_Click(Me, New System.EventArgs)
                Case llamadores.Contratos
                    Me.Hide()
                    Contratos.Show()
                    Contratos.Focus()
                    Contratos.txtNroProp.Text = Me.DataGridView1.SelectedCells.Item(0).Value
                    Contratos.btnBuscarPropiedad_Click(Me, New System.EventArgs)
                    Contratos.btnBuscarPropiedad_Click(Me, New System.EventArgs)
                Case llamadores.EstadoCuentas
                    'metodo 
                    Me.Hide()
                    EstadosCuentas.cargarDatosPropiedad(Me.DataGridView1.SelectedCells.Item(0).Value)
                    EstadosCuentas.cargarGrillaXPropiedad(Me.DataGridView1.SelectedCells.Item(0).Value)
                    EstadosCuentas.Show()
                    EstadosCuentas.Focus()

            End Select
        Catch ex As Exception
        End Try



    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub

    Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

    End Sub
End Class